package com.water.app.Controller.Order;
import com.water.app.Constant;
import com.water.app.Goods;
import com.water.app.Order;
import com.water.app.Result;

import com.water.app.interfaces.Order.OrderService;
import com.water.app.mapper.OrderMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

@RestController
@RequestMapping("/api")
public class OrderController {
    private static final Logger log = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    private OrderService orderService;

    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;
    @PostMapping("/selectOrder")
    public Result selectAll(){
        log.info("正在查询历史订单");
        Integer userId = Constant.THREAD_LOCAL.get();
        List<Order> list= orderService.selectAllOrders(userId);
        return Result.success(list);
    }
    @GetMapping("/receiveOrder")
    public Result receiveOrder(int goodeId){
        threadPoolExecutor.execute(()->{
            orderService.receiveOrder(goodeId);
        });
        return Result.success("订单处理成功");
    }
    @GetMapping("/getOrderShop")
    public Result getOrderShop(){
        List<Order> list = orderService.getOrderShopGoods();
        return Result.success(list);
    }
    @GetMapping("/getGoodsRelease")
    public Result getOrderRelease(){
        List<Goods> list = orderService.getGoodsRelease();
        return Result.success(list);
    }

}
